import java.util.HashMap;

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");

    }
}
class Solution {
    public int findMaxLength(int[] nums) {
        HashMap<Integer,Integer> hash = new HashMap<>();
        int sum = 0;
        int ret = 0;
        hash.put(0,-1);
        for (int i = 0,j = 0;i < nums.length;i++) {
            sum += (nums[i] == 0 ? -1 : 1);
            if (hash.containsKey(sum)) ret = Math.max(ret,i - hash.get(sum));
            else hash.put(sum,i);
        }
        return ret;
    }
}